home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / MiniExamples / ZooView / Controller.m < prev    next >
Text File  |  1991-09-10  |  2KB  |  90 lines

  1.  
  2. /* 
  3.  * Controller.m
  4.  *
  5.  * Purpose:
  6.  *        This object serves as the browsers delegate, and does some initialization.
  7.  *
  8.  * You may freely copy, distribute, and reuse the code in this example.
  9.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  10.  * fitness for any particular use.
  11.  *
  12.  * Written by: Mary McNabb
  13.  * Created: Apr 91
  14.  *
  15.  */
  16.  
  17. #import "Controller.h"
  18. #import "RightSubView.h"
  19. #import "SideSplitView.h"
  20. #import <appkit/Matrix.h>
  21. #import <appkit/Window.h>
  22. #import <appkit/NXBrowser.h>
  23. #import <appkit/NXBrowserCell.h>
  24. #import <appkit/Application.h>
  25.  
  26. #define MAXLEN 20        /* maximum number of chars in a name */
  27. #define NUM_ANIMALS 17     /* make sure this number matches the
  28.                          * number of strings in the following string table!! */
  29. char *animals[] = { "doug", "elizabeth", "flip", "george", "henry", "howard", "jeff", "julie", "kate", 
  30.     "leonard", "mai", "mary", "michelle", "sam", "sharon", "tony", "dawn" };
  31.  
  32. @implementation Controller
  33.  
  34. /*
  35.  * take advantage of IB and initialize the browser from here
  36.  */
  37. - setTheBrowser:anObject
  38. {
  39.     theBrowser = anObject;
  40.     [theBrowser setDelegate:self];
  41.     [theBrowser reloadColumn:0];
  42.     return self;
  43. }
  44.  
  45. /*
  46.  * Since we have to resize the subviews don't put the window on screen
  47.  * until we get here
  48.  */
  49. - appDidInit:sender
  50. {
  51.     [zooSplitView initViews];
  52.     [[zooSplitView window] orderFront:self];
  53.     return self;
  54. }
  55.  
  56. /*
  57.  * the user selected a name. Tell the right sub view to display the picture.
  58.  */
  59. - browserCellWasSelected:sender
  60. {
  61.     char path[MAXLEN];
  62.     char *p;
  63.  
  64.     [theBrowser getPath:path toColumn:1];
  65.     p = path; p++;            /* skip the separator which precedes the name */
  66.     [rightView setAnimalPicture:p];
  67.     return self;
  68. }
  69.  
  70. /*
  71.  * Fill the browser up with names from the string table.
  72.  */
  73. - (int)browser:sender fillMatrix:matrix inColumn:(int)column
  74. {
  75.     int i;
  76.     id newCell;
  77.     
  78.     for (i = 0; i < NUM_ANIMALS; i++) {
  79.         [matrix addRow];
  80.         newCell = [matrix cellAt:i :0];
  81.         [newCell setTag:(i * 16)];
  82.         [newCell setStringValue:animals[i]];
  83.         [newCell setLeaf:YES];
  84.         [newCell setLoaded:YES];
  85.     }
  86.     return i;
  87. }
  88.  
  89. @end
  90.